/*     */ package com.feeyin.radar.sys.service.impl;
/*     */ 
/*     */ import com.feeyin.radar.commons.DateUtils;
/*     */ import com.feeyin.radar.commons.StringUtils;
/*     */ import com.feeyin.radar.crm.dao.CustomerDAO;
/*     */ import com.feeyin.radar.crm.dao.CustomerShareDAO;
/*     */ import com.feeyin.radar.crm.dao.SaleRecordDAO;
/*     */ import com.feeyin.radar.crm.model.Customer;
/*     */ import com.feeyin.radar.msg.dao.WarningInfoDAO;
/*     */ import com.feeyin.radar.sys.dao.ManageSetDAO;
/*     */ import com.feeyin.radar.sys.dao.SaleStageSetDAO;
/*     */ import com.feeyin.radar.sys.form.CommonSettingsForm;
/*     */ import com.feeyin.radar.sys.model.ManageSet;
/*     */ import com.feeyin.radar.sys.model.SaleStageSet;
/*     */ import com.feeyin.radar.sys.service.CommonSettingsService;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Date;
/*     */ import java.util.List;
/*     */ 
/*     */ public class CommonSettingsServiceImpl
/*     */   implements CommonSettingsService
/*     */ {
/*     */   private ManageSetDAO manageSetDAO;
/*     */   private SaleStageSetDAO saleStageSetDAO;
/*     */   private CustomerDAO customerDAO;
/*     */   private CustomerShareDAO customerShareDAO;
/*     */   private WarningInfoDAO warningInfoDAO;
/*     */   private SaleRecordDAO saleRecordDAO;
/*     */ 
/*     */   public ManageSetDAO getManageSetDAO()
/*     */   {
/*  37 */     return this.manageSetDAO;
/*     */   }
/*     */ 
/*     */   public void setManageSetDAO(ManageSetDAO manageSetDAO) {
/*  41 */     this.manageSetDAO = manageSetDAO;
/*     */   }
/*     */ 
/*     */   public SaleStageSetDAO getSaleStageSetDAO() {
/*  45 */     return this.saleStageSetDAO;
/*     */   }
/*     */ 
/*     */   public void setSaleStageSetDAO(SaleStageSetDAO saleStageSetDAO) {
/*  49 */     this.saleStageSetDAO = saleStageSetDAO;
/*     */   }
/*     */ 
/*     */   public CustomerDAO getCustomerDAO() {
/*  53 */     return this.customerDAO;
/*     */   }
/*     */ 
/*     */   public void setCustomerDAO(CustomerDAO customerDAO) {
/*  57 */     this.customerDAO = customerDAO;
/*     */   }
/*     */ 
/*     */   public CustomerShareDAO getCustomerShareDAO() {
/*  61 */     return this.customerShareDAO;
/*     */   }
/*     */ 
/*     */   public void setCustomerShareDAO(CustomerShareDAO customerShareDAO) {
/*  65 */     this.customerShareDAO = customerShareDAO;
/*     */   }
/*     */ 
/*     */   public WarningInfoDAO getWarningInfoDAO() {
/*  69 */     return this.warningInfoDAO;
/*     */   }
/*     */ 
/*     */   public void setWarningInfoDAO(WarningInfoDAO warningInfoDAO) {
/*  73 */     this.warningInfoDAO = warningInfoDAO;
/*     */   }
/*     */ 
/*     */   public SaleRecordDAO getSaleRecordDAO() {
/*  77 */     return this.saleRecordDAO;
/*     */   }
/*     */ 
/*     */   public void setSaleRecordDAO(SaleRecordDAO saleRecordDAO) {
/*  81 */     this.saleRecordDAO = saleRecordDAO;
/*     */   }
/*     */ 
/*     */   public CommonSettingsForm getCommonSettings() {
/*  85 */     CommonSettingsForm commonSettingsForm = new CommonSettingsForm();
/*     */ 
/*  87 */     List list = new ArrayList();
/*  88 */     list = this.manageSetDAO.getActivityManageSets();
/*  89 */     if ((list == null) || (list.size() <= 0)) return commonSettingsForm;
/*     */ 
/*  91 */     for (int i = 0; i < list.size(); i++) {
/*  92 */       ManageSet manageSet = new ManageSet();
/*  93 */       manageSet = (ManageSet)list.get(i);
/*  94 */       if ("isUseCommon".equals(manageSet.getCode())) {
/*  95 */         commonSettingsForm.setIsUseCommon(manageSet.getStatus());
/*  96 */       } else if ("dueCustomer".equals(manageSet.getCode())) {
/*  97 */         commonSettingsForm.setDueCustomer(manageSet.getStatus());
/*  98 */       } else if ("agingSettings".equals(manageSet.getCode())) {
/*  99 */         commonSettingsForm.setAgingSettings(manageSet.getStatus());
/* 100 */         commonSettingsForm.setAgingDay(manageSet.getMValue());
/* 101 */         commonSettingsForm.getSaleStages().addAll(this.saleStageSetDAO.getSaleStages());
/* 102 */       } else if ("hisAgingSettings".equals(manageSet.getCode())) {
/* 103 */         commonSettingsForm.setHisAgingSettings(manageSet.getStatus());
/* 104 */         commonSettingsForm.setHisDay(manageSet.getMValue());
/* 105 */       } else if ("updateStatus".equals(manageSet.getCode())) {
/* 106 */         commonSettingsForm.setUpdateStatus(manageSet.getStatus());
/* 107 */       } else if ("customerInfoStatus".equals(manageSet.getCode())) {
/* 108 */         commonSettingsForm.setCustomerInfoStatus(manageSet.getStatus());
/* 109 */       } else if ("saleStageStatus".equals(manageSet.getCode())) {
/* 110 */         commonSettingsForm.setSaleStageStatus(manageSet.getStatus());
/* 111 */       } else if ("saleRecordStatus".equals(manageSet.getCode())) {
/* 112 */         commonSettingsForm.setSaleRecordStatus(manageSet.getStatus());
/*     */       }
/*     */     }
/*     */ 
/* 116 */     return commonSettingsForm;
/*     */   }
/*     */ 
/*     */   public int isUseCommons() {
/* 120 */     int result = 0;
/* 121 */     ManageSet manageSet = new ManageSet();
/* 122 */     manageSet.setMType("31");
/* 123 */     List list = new ArrayList();
/* 124 */     list = this.manageSetDAO.getManageSetByType("31");
/* 125 */     if ((list != null) && (list.size() > 0)) {
/* 126 */       manageSet = (ManageSet)list.get(0);
/* 127 */       if (manageSet != null) {
/* 128 */         result = Integer.parseInt(manageSet.getStatus());
/*     */       }
/*     */     }
/* 131 */     return result;
/*     */   }
/*     */ 
/*     */   public int isMoveToExceptionPool() {
/* 135 */     ManageSet manageSet = new ManageSet();
/* 136 */     manageSet = this.manageSetDAO.getManageSetByCode("dueCustomer");
/* 137 */     if (manageSet == null) return 0;
/*     */ 
/* 139 */     if ((!StringUtils.isEmpty(manageSet.getStatus())) && ("1".equals(manageSet.getStatus()))) {
/* 140 */       return 1;
/*     */     }
/* 142 */     return 0;
/*     */   }
/*     */ 
/*     */   public boolean updateCommonSettings(CommonSettingsForm commonSettingsForm) {
/* 146 */     if (commonSettingsForm == null) return false;
/* 147 */     if ((!StringUtils.isEmpty(commonSettingsForm.getIsUseDeptCommon())) && 
/* 148 */       ("2".equals(commonSettingsForm.getIsUseDeptCommon())))
/* 149 */       updateManageSet("isUseCommon", "2", null);
/*     */     else {
/* 151 */       updateManageSet("isUseCommon", commonSettingsForm.getIsUseCommon(), null);
/*     */     }
/* 153 */     updateManageSet("dueCustomer", commonSettingsForm.getDueCustomer(), null);
/* 154 */     String value1 = "";
/* 155 */     if ("0".equals(commonSettingsForm.getAgingSettings())) {
/* 156 */       value1 = commonSettingsForm.getAgingDay();
/*     */     }
/* 158 */     updateManageSet("agingSettings", commonSettingsForm.getAgingSettings(), value1);
/* 159 */     if ("1".equals(commonSettingsForm.getAgingSettings())) {
/* 160 */       updateSaleStage(commonSettingsForm.getSaleStageId(), commonSettingsForm.getUsefulTime());
/*     */     }
/* 162 */     String value2 = "";
/* 163 */     if ("1".equals(commonSettingsForm.getHisAgingSettings())) {
/* 164 */       value2 = commonSettingsForm.getHisDay();
/*     */     }
/* 166 */     updateManageSet("hisAgingSettings", commonSettingsForm.getHisAgingSettings(), value2);
/* 167 */     updateManageSet("updateStatus", commonSettingsForm.getUpdateStatus(), null);
/* 168 */     if ("1".equals(commonSettingsForm.getUpdateStatus())) {
/* 169 */       updateManageSet("customerInfoStatus", commonSettingsForm.getCustomerInfoStatus(), null);
/* 170 */       updateManageSet("saleStageStatus", commonSettingsForm.getSaleStageStatus(), null);
/* 171 */       updateManageSet("saleRecordStatus", commonSettingsForm.getSaleRecordStatus(), null);
/*     */     } else {
/* 173 */       updateManageSet("customerInfoStatus", "0", null);
/* 174 */       updateManageSet("saleStageStatus", "0", null);
/* 175 */       updateManageSet("saleRecordStatus", "0", null);
/*     */     }
/* 177 */     return true;
/*     */   }
/*     */ 
/*     */   private boolean updateManageSet(String code, String status, String value)
/*     */   {
/* 182 */     boolean result = false;
/* 183 */     ManageSet manageSet = new ManageSet();
/* 184 */     if (!StringUtils.isEmpty(code)) {
/* 185 */       manageSet.setCode(code);
/* 186 */       if (!StringUtils.isEmpty(status))
/* 187 */         manageSet.setStatus(status);
/*     */       else {
/* 189 */         manageSet.setStatus("0");
/*     */       }
/* 191 */       if (!StringUtils.isEmpty(value))
/* 192 */         manageSet.setMValue(value);
/*     */       else {
/* 194 */         manageSet.setMValue("0");
/*     */       }
/* 196 */       result = this.manageSetDAO.updateManageSetByCode(manageSet);
/*     */     }
/* 198 */     return result;
/*     */   }
/*     */ 
/*     */   private boolean updateSaleStage(Integer[] saleStageId, Integer[] usefulTime)
/*     */   {
/* 203 */     if ((saleStageId == null) || (usefulTime == null)) return false;
/*     */ 
/* 205 */     for (int i = 0; i < saleStageId.length; i++) {
/* 206 */       SaleStageSet saleStageSet = new SaleStageSet();
/* 207 */       saleStageSet.setId(saleStageId[i]);
/* 208 */       saleStageSet.setUsefulTime(usefulTime[i]);
/* 209 */       this.saleStageSetDAO.updateSaleStage(saleStageSet);
/*     */     }
/* 211 */     return true;
/*     */   }
/*     */ 
/*     */   public boolean moveOverDueCustomers()
/*     */   {
/* 228 */     CommonSettingsForm commonSettingsForm = new CommonSettingsForm();
/* 229 */     commonSettingsForm = getCommonSettings();
/* 230 */     if (commonSettingsForm == null) return false;
/* 231 */     if ((!"1".equals(commonSettingsForm.getIsUseCommon())) && 
/* 232 */       (!"2".equals(commonSettingsForm.getIsUseCommon()))) return false;
/*     */ 
/* 234 */     Customer customer = new Customer();
/*     */ 
/* 236 */     customer.setCategorys("1");
/* 237 */     customer.setSaleStatus("0");
/* 238 */     List customers = new ArrayList();
/* 239 */     customers = this.customerDAO.getCustomersByDynamic(customer);
/* 240 */     if (customers == null) return false;
/*     */ 
/* 242 */     String moveSign = commonSettingsForm.getDueCustomer();
/* 243 */     String agingSign = commonSettingsForm.getAgingSettings();
/*     */ 
/* 246 */     for (int i = 0; i < customers.size(); i++) {
/* 247 */       boolean result = false;
/* 248 */       long agingDay = 0L;
/* 249 */       Date agingDate = null;
/* 250 */       customer = new Customer();
/* 251 */       customer = (Customer)customers.get(i);
/*     */ 
/* 253 */       Customer paramCustomer = new Customer();
/* 254 */       paramCustomer.setId(customer.getId());
/* 255 */       paramCustomer.setExceptionReason("1");
/* 256 */       if ("1".equals(moveSign)) {
/* 257 */         paramCustomer.setCustomerCategory("2");
/*     */       } else {
/* 259 */         paramCustomer.setCustomerCategory("0");
/* 260 */         paramCustomer.setPersonId(Integer.valueOf(0));
/* 261 */         paramCustomer.setSaleStageId(Integer.valueOf(0));
/*     */       }
/*     */ 
/* 264 */       if (("1".equals(agingSign)) && (customer.getSaleStageId() != null) && (customer.getSaleStageId().intValue() != 0)) {
/* 265 */         if (commonSettingsForm.getSaleStages() != null) {
/* 266 */           agingDay = Long.parseLong(getSaleStageAgingDay(commonSettingsForm.getSaleStages(), customer.getSaleStageId().toString()));
/*     */         }
/* 268 */         agingDate = DateUtils.getDateSubtractDay(new Date(), agingDay); } else {
/* 269 */         if (!"0".equals(agingSign)) continue;
/* 270 */         if (!StringUtils.isEmpty(commonSettingsForm.getAgingDay())) {
/* 271 */           agingDay = Long.parseLong(commonSettingsForm.getAgingDay());
/*     */         }
/* 273 */         agingDate = DateUtils.getDateSubtractDay(new Date(), agingDay);
/*     */       }
/*     */ 
/* 278 */       if ("1".equals(commonSettingsForm.getUpdateStatus())) {
/* 279 */         paramCustomer.setAgingDate(agingDate);
/*     */ 
/* 281 */         if (("1".equals(commonSettingsForm.getCustomerInfoStatus())) && 
/* 282 */           (customer.getUpdateCustomerDate() != null) && (customer.getUpdateCustomerDate().compareTo(agingDate) < 0)) {
/* 283 */           paramCustomer.setAgingCustomerDate(agingDate);
/*     */         }
/* 285 */         if (("1".equals(commonSettingsForm.getSaleStageStatus())) && 
/* 286 */           (customer.getUpdateSaleStageDate() != null) && (customer.getUpdateSaleStageDate().compareTo(agingDate) < 0)) {
/* 287 */           paramCustomer.setAgingSaleStageDate(agingDate);
/*     */         }
/* 289 */         if (("1".equals(commonSettingsForm.getSaleRecordStatus())) && 
/* 290 */           (customer.getUpdateSaleRecordDate() != null) && (customer.getUpdateSaleRecordDate().compareTo(agingDate) < 0)) {
/* 291 */           paramCustomer.setAgingSaleRecordDate(agingDate);
/*     */         }
/* 293 */         if ((agingDate != null) && ((paramCustomer.getAgingCustomerDate() != null) || 
/* 294 */           (paramCustomer.getAgingSaleStageDate() != null) || (paramCustomer.getAgingSaleRecordDate() != null)))
/* 295 */           result = this.customerDAO.updateCustomerByParam(paramCustomer);
/*     */       }
/*     */       else
/*     */       {
/* 299 */         if ((customer.getUpdateCustomerDate() != null) && (customer.getUpdateCustomerDate().compareTo(agingDate) < 0)) {
/* 300 */           paramCustomer.setUpdateCustomerDate(agingDate);
/*     */         }
/* 302 */         if ((customer.getUpdateSaleStageDate() != null) && (customer.getUpdateSaleStageDate().compareTo(agingDate) < 0)) {
/* 303 */           paramCustomer.setUpdateSaleStageDate(agingDate);
/*     */         }
/* 305 */         if ((customer.getUpdateSaleRecordDate() != null) && (customer.getUpdateSaleRecordDate().compareTo(agingDate) < 0)) {
/* 306 */           paramCustomer.setUpdateSaleRecordDate(agingDate);
/*     */         }
/*     */ 
/* 309 */         if ((agingDate != null) && ((paramCustomer.getUpdateCustomerDate() != null) || 
/* 310 */           (paramCustomer.getUpdateSaleStageDate() != null) || (paramCustomer.getUpdateSaleRecordDate() != null))) {
/* 311 */           result = this.customerDAO.updateCustomerByParam(paramCustomer);
/*     */         }
/*     */ 
/*     */       }
/*     */ 
/* 318 */       if (result) {
/* 319 */         Customer curCustomer = new Customer();
/* 320 */         curCustomer = this.customerDAO.getCustomerById(customer.getId());
/* 321 */         if ((curCustomer != null) && (
/* 322 */           ("0".equals(curCustomer.getCustomerCategory())) || 
/* 323 */           ("2".equals(curCustomer.getCustomerCategory())))) {
/* 324 */           this.customerShareDAO.deleteCustomerShare(customer.getId());
/* 325 */           this.customerDAO.updateCustomerShare(customer.getId(), "0");
/*     */ 
/* 331 */           if ((StringUtils.isEmpty(curCustomer.getSaleStatus())) || ("0".equals(curCustomer.getSaleStatus()))) {
/* 332 */             List saleRecords = new ArrayList();
/* 333 */             saleRecords = this.saleRecordDAO.getSaleRecordsByCustomerIdAndStatus(customer.getId(), "0");
/* 334 */             if ((saleRecords != null) && (saleRecords.size() > 0)) {
/* 335 */               Customer c = new Customer();
/* 336 */               c.setId(customer.getId());
/* 337 */               c.setSaleStatus("2");
/* 338 */               this.customerDAO.updateCustomer(c);
/*     */             }
/*     */           }
/*     */ 
/*     */         }
/*     */ 
/* 344 */         this.warningInfoDAO.insertMoveCustomerWarningInfo(customer);
/*     */       }
/*     */     }
/*     */ 
/* 348 */     moveOverDueContractCustomers();
/*     */ 
/* 350 */     return true;
/*     */   }
/*     */ 
/*     */   private boolean moveOverDueContractCustomers()
/*     */   {
/* 358 */     CommonSettingsForm commonSettingsForm = new CommonSettingsForm();
/* 359 */     commonSettingsForm = getCommonSettings();
/* 360 */     if (commonSettingsForm == null) return false;
/* 361 */     if ((!"1".equals(commonSettingsForm.getIsUseCommon())) && 
/* 362 */       (!"2".equals(commonSettingsForm.getIsUseCommon()))) return false;
/*     */ 
/* 364 */     Customer customer = new Customer();
/* 365 */     customer.setCategorys("3");
/* 366 */     List customers = new ArrayList();
/* 367 */     customers = this.customerDAO.getCustomersByDynamic(customer);
/* 368 */     if (customers == null) return false;
/*     */ 
/* 370 */     String moveSign = commonSettingsForm.getDueCustomer();
/* 371 */     String hisAgingSign = commonSettingsForm.getHisAgingSettings();
/*     */ 
/* 373 */     for (int i = 0; i < customers.size(); i++) {
/* 374 */       boolean result = false;
/* 375 */       long agingDay = 0L;
/* 376 */       Date agingDate = null;
/* 377 */       customer = new Customer();
/* 378 */       customer = (Customer)customers.get(i);
/*     */ 
/* 380 */       Customer paramCustomer = new Customer();
/* 381 */       paramCustomer.setId(customer.getId());
/* 382 */       paramCustomer.setExceptionReason("1");
/* 383 */       if ("1".equals(moveSign)) {
/* 384 */         paramCustomer.setCustomerCategory("2");
/*     */       } else {
/* 386 */         paramCustomer.setCustomerCategory("0");
/* 387 */         paramCustomer.setPersonId(Integer.valueOf(0));
/* 388 */         paramCustomer.setSaleStageId(Integer.valueOf(0));
/*     */       }
/*     */ 
/* 391 */       if ((!StringUtils.isEmpty(hisAgingSign)) && ("1".equals(hisAgingSign))) {
/* 392 */         if (!StringUtils.isEmpty(commonSettingsForm.getHisDay())) {
/* 393 */           agingDay = Long.parseLong(commonSettingsForm.getHisDay());
/*     */         }
/* 395 */         agingDate = DateUtils.getDateSubtractDay(new Date(), agingDay);
/*     */ 
/* 398 */         Date lastLinkCare = null;
/* 399 */         lastLinkCare = this.saleRecordDAO.getSaleRecordLastLinkByCustomerIdAndStatus(customer.getId(), "2");
/*     */ 
/* 401 */         if ((lastLinkCare != null) && (agingDate != null) && 
/* 402 */           (lastLinkCare.compareTo(agingDate) < 0))
/*     */         {
/* 404 */           result = this.customerDAO.updateCustomerByParam(paramCustomer);
/*     */         }
/*     */ 
/* 409 */         if (result) {
/* 410 */           Customer curCustomer = new Customer();
/* 411 */           curCustomer = this.customerDAO.getCustomerById(customer.getId());
/* 412 */           if ((curCustomer != null) && (
/* 413 */             ("0".equals(curCustomer.getCustomerCategory())) || 
/* 414 */             ("2".equals(curCustomer.getCustomerCategory())))) {
/* 415 */             this.customerShareDAO.deleteCustomerShare(customer.getId());
/* 416 */             this.customerDAO.updateCustomerShare(customer.getId(), "0");
/*     */           }
/*     */ 
/* 420 */           this.warningInfoDAO.insertMoveCustomerWarningInfo(customer);
/*     */         }
/*     */       }
/*     */     }
/*     */ 
/* 425 */     return true;
/*     */   }
/*     */ 
/*     */   public boolean warningOverDueCustomers() {
/* 429 */     CommonSettingsForm commonSettingsForm = new CommonSettingsForm();
/* 430 */     commonSettingsForm = getCommonSettings();
/* 431 */     if (commonSettingsForm == null) return false;
/* 432 */     if ((!"1".equals(commonSettingsForm.getIsUseCommon())) && 
/* 433 */       (!"2".equals(commonSettingsForm.getIsUseCommon()))) return false;
/*     */ 
/* 435 */     Customer customer = new Customer();
/*     */ 
/* 437 */     customer.setCategorys("1");
/* 438 */     customer.setSaleStatus("0");
/* 439 */     List customers = new ArrayList();
/* 440 */     customers = this.customerDAO.getCustomersByDynamic(customer);
/* 441 */     if (customers == null) return false;
/*     */ 
/* 443 */     String agingSign = commonSettingsForm.getAgingSettings();
/* 444 */     for (int i = 0; i < customers.size(); i++) {
/* 445 */       boolean result = false;
/* 446 */       long agingDay = 0L;
/* 447 */       Date agingDate = null;
/* 448 */       customer = new Customer();
/* 449 */       customer = (Customer)customers.get(i);
/*     */ 
/* 451 */       if (("1".equals(agingSign)) && (customer.getSaleStageId() != null) && (customer.getSaleStageId().intValue() != 0)) {
/* 452 */         if (commonSettingsForm.getSaleStages() != null) {
/* 453 */           agingDay = Long.parseLong(getSaleStageAgingDay(commonSettingsForm.getSaleStages(), customer.getSaleStageId().toString()));
/*     */         }
/* 455 */         agingDate = DateUtils.getDateSubtractDay(new Date(), agingDay); } else {
/* 456 */         if (!"0".equals(agingSign)) continue;
/* 457 */         if (!StringUtils.isEmpty(commonSettingsForm.getAgingDay())) {
/* 458 */           agingDay = Long.parseLong(commonSettingsForm.getAgingDay());
/*     */         }
/* 460 */         agingDate = DateUtils.getDateSubtractDay(new Date(), agingDay);
/*     */       }
/*     */ 
/* 465 */       long warningDayByCustomer = DateUtils.getDayByTwoDate(customer.getUpdateCustomerDate(), agingDate);
/* 466 */       long warningDayBySaleStage = DateUtils.getDayByTwoDate(customer.getUpdateSaleStageDate(), agingDate);
/* 467 */       long warningDayBySaleRecord = DateUtils.getDayByTwoDate(customer.getUpdateSaleRecordDate(), agingDate);
/* 468 */       if ("1".equals(commonSettingsForm.getUpdateStatus())) {
/* 469 */         if (("1".equals(commonSettingsForm.getCustomerInfoStatus())) && 
/* 470 */           (warningDayByCustomer <= 3L) && (warningDayByCustomer >= 0L)) {
/* 471 */           this.warningInfoDAO.insertWarningOverDueCustomer(customer, warningDayByCustomer);
/* 472 */         } else if (("1".equals(commonSettingsForm.getSaleStageStatus())) && 
/* 473 */           (warningDayBySaleStage <= 3L) && (warningDayBySaleStage >= 0L)) {
/* 474 */           this.warningInfoDAO.insertWarningOverDueCustomer(customer, warningDayBySaleStage); } else {
/* 475 */           if ((!"1".equals(commonSettingsForm.getSaleRecordStatus())) || 
/* 476 */             (warningDayBySaleRecord > 3L) || (warningDayBySaleRecord < 0L)) continue;
/* 477 */           this.warningInfoDAO.insertWarningOverDueCustomer(customer, warningDayBySaleRecord);
/*     */         }
/*     */       }
/*     */       else {
/* 481 */         if ((warningDayByCustomer > 3L) || (warningDayByCustomer < 0L) || 
/* 482 */           (warningDayBySaleStage > 3L) || (warningDayBySaleStage < 0L) || 
/* 483 */           (warningDayBySaleRecord > 3L) || (warningDayBySaleRecord < 0L)) continue;
/* 484 */         long warningDay = warningDayByCustomer;
/* 485 */         if (warningDayBySaleStage < warningDayByCustomer) {
/* 486 */           warningDay = warningDayBySaleStage;
/* 487 */           if (warningDayBySaleRecord < warningDayBySaleStage)
/* 488 */             warningDay = warningDayBySaleRecord;
/*     */         }
/* 490 */         else if (warningDayBySaleRecord < warningDayByCustomer) {
/* 491 */           warningDay = warningDayBySaleRecord;
/*     */         }
/* 493 */         this.warningInfoDAO.insertWarningOverDueCustomer(customer, warningDay);
/*     */       }
/*     */ 
/*     */     }
/*     */ 
/* 498 */     warningOverDueContractCustomers();
/*     */ 
/* 500 */     return true;
/*     */   }
/*     */ 
/*     */   public boolean warningOverDueContractCustomers()
/*     */   {
/* 508 */     CommonSettingsForm commonSettingsForm = new CommonSettingsForm();
/* 509 */     commonSettingsForm = getCommonSettings();
/* 510 */     if (commonSettingsForm == null) return false;
/* 511 */     if ((!"1".equals(commonSettingsForm.getIsUseCommon())) && 
/* 512 */       (!"2".equals(commonSettingsForm.getIsUseCommon()))) return false;
/*     */ 
/* 514 */     Customer customer = new Customer();
/* 515 */     customer.setCategorys("3");
/* 516 */     List customers = new ArrayList();
/* 517 */     customers = this.customerDAO.getCustomersByDynamic(customer);
/* 518 */     if (customers == null) return false;
/*     */ 
/* 520 */     String hisAgingSign = commonSettingsForm.getHisAgingSettings();
/* 521 */     for (int i = 0; i < customers.size(); i++) {
/* 522 */       boolean result = false;
/* 523 */       long agingDay = 0L;
/* 524 */       Date agingDate = null;
/* 525 */       customer = new Customer();
/* 526 */       customer = (Customer)customers.get(i);
/*     */ 
/* 528 */       if ((!StringUtils.isEmpty(hisAgingSign)) && ("1".equals(hisAgingSign))) {
/* 529 */         if (!StringUtils.isEmpty(commonSettingsForm.getHisDay())) {
/* 530 */           agingDay = Long.parseLong(commonSettingsForm.getHisDay());
/*     */         }
/* 532 */         agingDate = DateUtils.getDateSubtractDay(new Date(), agingDay);
/*     */ 
/* 535 */         Date lastLinkCare = null;
/* 536 */         lastLinkCare = this.saleRecordDAO.getSaleRecordLastLinkByCustomerIdAndStatus(customer.getId(), "2");
/*     */ 
/* 538 */         if ((lastLinkCare != null) && (agingDate != null)) {
/* 539 */           long warningDay = DateUtils.getDayByTwoDate(lastLinkCare, agingDate);
/* 540 */           if ((warningDay < 0L) || (warningDay > 3L))
/*     */             continue;
/* 542 */           this.warningInfoDAO.insertWarningOverDueCustomer(customer, warningDay);
/*     */         }
/*     */       }
/*     */ 
/*     */     }
/*     */ 
/* 548 */     return true;
/*     */   }
/*     */ 
/*     */   public boolean moveToExceptionCustomer() {
/* 552 */     Customer customer = new Customer();
/* 553 */     customer.setCategorys("0");
/* 554 */     customer.setCustomerCategory("2");
/* 555 */     customer.setExceptionReason("4");
/* 556 */     return this.customerDAO.updateCustomerByParam(customer);
/*     */   }
/*     */ 
/*     */   private String getSaleStageAgingDay(List saleStages, String stageCode)
/*     */   {
/* 566 */     String agingDay = "0";
/* 567 */     if (saleStages == null) return agingDay;
/* 568 */     if (StringUtils.isEmpty(stageCode)) return agingDay;
/*     */ 
/* 570 */     for (int i = 0; i < saleStages.size(); i++) {
/* 571 */       SaleStageSet saleStage = new SaleStageSet();
/* 572 */       saleStage = (SaleStageSet)saleStages.get(i);
/* 573 */       if ((saleStage.getUsefulTime() == null) || 
/* 574 */         (!stageCode.equals(saleStage.getStageCode()))) continue;
/* 575 */       agingDay = saleStage.getUsefulTime().toString();
/*     */     }
/*     */ 
/* 578 */     return agingDay;
/*     */   }
/*     */ }

/* Location:           C:\Users\e547415\MyProject\rone\WEB-INF\classes\
 * Qualified Name:     com.feeyin.radar.sys.service.impl.CommonSettingsServiceImpl
 * JD-Core Version:    0.6.0
 */